import md5 from 'js-md5';
import dayjs from 'dayjs'
import axios from "axios";

let nowDate;
let TimeStamp;
const apiBase = process.env.VUE_APP_API_BASE_URL || '';

export const getrequest = (url, params ={}) => {
  nowDate = dayjs(new Date().getTime()).format('YYYY-MM-DD HH:mm:ss');
  TimeStamp = dayjs(nowDate).unix();
  params['params'].TimeStamp = TimeStamp
  return axios({
    method: 'get',
    url,
    params: params['params'],
    baseURL: location.protocol === 'http:'? apiBase.replace('https:', 'http:'): apiBase,
    headers: {
      ZDAN_Token: md5(params['params'].Passwd + params['params'].StreamID + TimeStamp )
    },
    timeout: 30 * 1000,
  })
}
// export const postrequest = (url, query ={}) => {
//   nowDate = dayjs(new Date().getTime()).format('YYYY-MM-DD HH:mm:ss');
//   TimeStamp = dayjs(nowDate).unix();
//   Object.assign(query, TimeStamp)
//   await axios({
//     method: 'post',
//     url
//     data: query,
//     baseURL: location.protocol === 'http:'? apiBase.replace('https:', 'http:'): apiBase,
//     headers: {
//       ZDAN_Token: md5(query.Passwd + query.StreamID + TimeStamp )
//     },
//     timeout: 30 * 1000,
//   }).then(res => {
//     return res
//   })
// }